package com.c35.ajax.dwr;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class DwrDemoService {

    private static String[] usernameList = new String[] { "yushan", "shuany", "shuanys" };

    public boolean checkUsername(String username) {
        return isContain(username);
    }

    public boolean isContain(String param) {
        for (String username : usernameList) {
            if (username.toLowerCase().equals(param)) {
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        boolean[] boolArray = new boolean[] { true, false, true };
        JSONArray jsonArray1 = JSONArray.fromObject(boolArray);
        System.out.println(jsonArray1);

        List list = new ArrayList();
        list.add("first");
        list.add("second");
        JSONArray jsonArray2 = JSONArray.fromObject(list);
        System.out.println(jsonArray2);

        JSONArray jsonArray3 = JSONArray.fromObject("['json','is','easy']");
        System.out.println(jsonArray3);

        Map map = new HashMap();
        map.put("name", "json");
        map.put("bool", Boolean.TRUE);

        map.put("int", new Integer(1));
        map.put("arr", new String[] { "a", "b" });
        map.put("func", "function(i){ return this.arr[i]; }");
        JSONObject json = JSONObject.fromObject(map);
        System.out.println(json);

    }
}
